package cn.edu.cqu.bysj.wm.gui.table;

import java.util.Collections;
import java.util.List;

import javax.swing.JOptionPane;

import cn.edu.cqu.bysj.wm.gui.component.JDTotalTabPane;
import cn.edu.cqu.bysj.wm.gui.result.NodeRankRow;

import mySwingToolkit.controller.TableController;
import mySwingToolkit.model.ClassModel;
import mySwingToolkit.model.SwitchedTableModel;
import mySwingToolkit.ui.TableView;

public class NodeRankView extends TableView<NodeRankRow> {
	/**
	 * create node rank view table
	 * 
	 * @param title
	 * @param heads
	 * @param classes
	 * @param booleans
	 * @param pagesize
	 */
	public NodeRankView(String title, String[] heads,
			@SuppressWarnings("rawtypes") Class[] classes, boolean[] booleans,
			int pagesize) {

		super(new SwitchedTableModel<NodeRankRow>(new Object[][] {}, heads,
				classes, booleans, false, false, false, pagesize) {
			@Override
			public Object[] translate(ClassModel<NodeRankRow> object) {
				NodeRankRow c = object.getObject();
				Object[] objs = new Object[this.getColumnNames().length];
				objs[0] = object;
				objs[1] = this.getRowCount() + 1;
				for (int i = 2; i < this.getColumnNames().length; i++) {
					String columnName = this.getColumnName(i);

					if (columnName.equals(JDTotalTabPane.DEGREE_CENTRALITY)) {
						objs[i] = c.getDegree();
					} else if (columnName
							.equals(JDTotalTabPane.BETWEENNESS_CENTRALITY)) {
						objs[i] = c.getBetweenness();
					} else if (columnName
							.equals(JDTotalTabPane.STRESS_CENTRALITY)) {
						objs[i] = c.getStress();
					} else if (columnName
							.equals(JDTotalTabPane.CLOSENESS_CENTRALITY)) {
						objs[i] = c.getCloseness();
					} else if (columnName
							.equals(JDTotalTabPane.CLUSTER_COEFFICIENT)) {
						objs[i] = c.getCluster();
					} else if (columnName.equals(JDTotalTabPane.PAGE_RANK)) {
						objs[i] = c.getPagerank();
					}
				}
				return objs;
			}

			@Override
			public NodeRankRow constructObject(int row, int col) {
				@SuppressWarnings("unchecked")
				ClassModel<NodeRankRow> cm = (ClassModel<NodeRankRow>) this
						.getValueAt(row, 0);
				NodeRankRow cr = null;
				if (cm != null) {
					cr = cm.getObject();
				} else {
					cr = new NodeRankRow();
				}
				switch (col) {
				case 2:
					break;
				case 3:
					break;
				case 4:
					break;
				case 5:
					break;
				case 6:
					break;
				}
				return cr;
			}

			@Override
			public void initNullRow(int row) {
				// this.setValueAt("男", row, 4);
			}
		}, title);
		// 加入数据
		this.initDatas(Collections.singletonList(new NodeRankRow()));
		// 设置tc
		this.setTableController(new TableController<NodeRankRow>() {
			@Override
			public List<NodeRankRow> getBackupDatas(
					SwitchedTableModel<NodeRankRow> tm) {
				JOptionPane.showMessageDialog(null, "暂不支持");
				return null;
			}

			@Override
			public boolean saveChanges(SwitchedTableModel<NodeRankRow> tm) {
				System.out.println(tm.getInsertDatas().size());
				return true;
			}
		});
	}

}
